package com.smarthospital.web.controller;

import com.alibaba.fastjson.JSON;
import com.smarthospital.common.Result.ResultDTO;
import com.smarthospital.entity.pojo.User;
import com.smarthospital.entity.vo.UserVO;
import com.smarthospital.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * create by sym  2020/8/16 16:00.
 */
@RestController
@Slf4j
@RequestMapping("/user")
@Api(description = "用户接口",value = "user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getUser")
    @ApiOperation(value = "查询用户")
    public ResultDTO getUser(@RequestHeader("SH_TOKEN")String SH_TOKEN){
        User user = userService.getUser();
        return ResultDTO.sucess(user);
    }

    @GetMapping("/userInfo")
    @ApiOperation(value = "用户信息，用于展示")
    public ResultDTO userInfo(@RequestHeader("SH_TOKEN")String SH_TOKEN){
        User user = userService.userInfo();
        return ResultDTO.sucess(user);
    }

    @PostMapping("/updateUser")
    @ApiOperation(value = "提交用户信息")
    public ResultDTO updateUser(@RequestBody UserVO user, @RequestHeader("SH_TOKEN")String SH_TOKEN){
        log.info("updateUser param {}", JSON.toJSONString(user));
        userService.updateUser(user);
        return ResultDTO.sucess();
    }
}
